package com.lfd.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lfd.entity.Product;
import com.lfd.service.TjProductService;
import com.lfd.util.Result;
import com.lfd.vo.ProductVo;

@Controller
@RequestMapping("/tjshop")
public class TjProductController {

	private final Logger logger = Logger.getLogger(TjProductController.class);
	@Autowired
	private TjProductService tjProductService;
/**
 * 显示所有
 * @param productVo
 * @param page
 * @param limit
 * @return
 */
	@ResponseBody
	@RequestMapping("/list")
	public Result tuijia(ProductVo productVo, @RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "limit", defaultValue = "10") Integer limit) {
		List<ProductVo> tuijian = new ArrayList();
		try {
			tuijian = tjProductService.tuijian(productVo, page, limit);
		} catch (Exception e) {

			logger.error("异常", e);
			return new Result("1", "失败");

		}

		return new Result("0", "成功", 100, tuijian);

	}
/**
 * 取消推荐
 * @param ids
 * @return
 */
	@ResponseBody
    @RequestMapping("/update")
	public Result update(@RequestParam("ids") List<Long> ids) {
		try {
			tjProductService.update(ids);
		} catch (Exception e) {
			logger.error("失败", e);
			return new Result("1", "失败");
		}
		return new Result("0", "成功");

	}


	/**
	 * 设置推荐
	 * @param ids
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/sztuijian")
	
	public Result sztuijian(@RequestParam("ids") List<Long> ids) {
		try {
			tjProductService.update(ids);
		} catch (Exception e) {
			logger.error("失败", e);
			return new Result("1", "失败");
		}
		return new Result("0", "成功");

	}
}
